<!DOCTYPE html>
<html lang="en-us">
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    
<meta charset="UTF-8">
<title>Ranking Evaluation API | Elasticsearch Guide [7.7] | Elastic</title>
<link rel="home" href="index.html" title="Elasticsearch Guide [7.7]">
<link rel="up" href="search.html" title="Search APIs">
<link rel="prev" href="search-field-caps.html" title="Field Capabilities API">
<link rel="next" href="security-api.html" title="Security APIs">
<meta name="DC.type" content="Learn/Docs/Elasticsearch/Reference/7.7">
<meta name="DC.subject" content="Elasticsearch">
<meta name="DC.identifier" content="7.7">
<meta name="robots" content="noindex,nofollow">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://cdn.optimizely.com/js/18132920325.js"></script>
    <link rel="apple-touch-icon" sizes="57x57" href="/apple-icon-57x57.png">
    <link rel="apple-touch-icon" sizes="60x60" href="/apple-icon-60x60.png">
    <link rel="apple-touch-icon" sizes="72x72" href="/apple-icon-72x72.png">
    <link rel="apple-touch-icon" sizes="76x76" href="/apple-icon-76x76.png">
    <link rel="apple-touch-icon" sizes="114x114" href="/apple-icon-114x114.png">
    <link rel="apple-touch-icon" sizes="120x120" href="/apple-icon-120x120.png">
    <link rel="apple-touch-icon" sizes="144x144" href="/apple-icon-144x144.png">
    <link rel="apple-touch-icon" sizes="152x152" href="/apple-icon-152x152.png">
    <link rel="apple-touch-icon" sizes="180x180" href="/apple-icon-180x180.png">
    <link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32">
    <link rel="icon" type="image/png" href="/android-chrome-192x192.png" sizes="192x192">
    <link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96">
    <link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16">
    <link rel="manifest" href="/manifest.json">
    <meta name="apple-mobile-web-app-title" content="Elastic">
    <meta name="application-name" content="Elastic">
    <meta name="msapplication-TileColor" content="#ffffff">
    <meta name="msapplication-TileImage" content="/mstile-144x144.png">
    <meta name="theme-color" content="#ffffff">
    <meta name="naver-site-verification" content="936882c1853b701b3cef3721758d80535413dbfd">
    <meta name="yandex-verification" content="d8a47e95d0972434">
    <meta name="localized" content="true">
    <meta name="st:robots" content="follow,index">
    <meta property="og:image" content="https://www.elastic.co/static/images/elastic-logo-200.png">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
    <link rel="icon" href="/favicon.ico" type="image/x-icon">
    <link rel="apple-touch-icon-precomposed" sizes="64x64" href="/favicon_64x64_16bit.png">
    <link rel="apple-touch-icon-precomposed" sizes="32x32" href="/favicon_32x32.png">
    <link rel="apple-touch-icon-precomposed" sizes="16x16" href="/favicon_16x16.png">
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="/guide/static/styles.css">
  </head>

  <!--© 2015-2021 Elasticsearch B.V. Copying, publishing and/or distributing without written permission is strictly prohibited.-->

  <body>
    <!-- Google Tag Manager -->
    <script>dataLayer = [];</script><noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-58RLH5" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
    <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-58RLH5');</script>
    <!-- End Google Tag Manager -->

    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-12395217-16"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
      gtag('config', 'UA-12395217-16');
    </script>

    <!--BEGIN QUALTRICS WEBSITE FEEDBACK SNIPPET-->
    <script type="text/javascript">
      (function(){var g=function(e,h,f,g){
      this.get=function(a){for(var a=a+"=",c=document.cookie.split(";"),b=0,e=c.length;b<e;b++){for(var d=c[b];" "==d.charAt(0);)d=d.substring(1,d.length);if(0==d.indexOf(a))return d.substring(a.length,d.length)}return null};
      this.set=function(a,c){var b="",b=new Date;b.setTime(b.getTime()+6048E5);b="; expires="+b.toGMTString();document.cookie=a+"="+c+b+"; path=/; "};
      this.check=function(){var a=this.get(f);if(a)a=a.split(":");else if(100!=e)"v"==h&&(e=Math.random()>=e/100?0:100),a=[h,e,0],this.set(f,a.join(":"));else return!0;var c=a[1];if(100==c)return!0;switch(a[0]){case "v":return!1;case "r":return c=a[2]%Math.floor(100/c),a[2]++,this.set(f,a.join(":")),!c}return!0};
      this.go=function(){if(this.check()){var a=document.createElement("script");a.type="text/javascript";a.src=g;document.body&&document.body.appendChild(a)}};
      this.start=function(){var a=this;window.addEventListener?window.addEventListener("load",function(){a.go()},!1):window.attachEvent&&window.attachEvent("onload",function(){a.go()})}};
      try{(new g(100,"r","QSI_S_ZN_emkP0oSe9Qrn7kF","https://znemkp0ose9qrn7kf-elastic.siteintercept.qualtrics.com/WRSiteInterceptEngine/?Q_ZID=ZN_emkP0oSe9Qrn7kF")).start()}catch(i){}})();
    </script><div id="ZN_emkP0oSe9Qrn7kF"><!--DO NOT REMOVE-CONTENTS PLACED HERE--></div>
    <!--END WEBSITE FEEDBACK SNIPPET-->

    <div id="elastic-nav" style="display:none;"></div>
    <script src="https://www.elastic.co/elastic-nav.js"></script>

    <!-- Subnav -->
    <div>
      <div>
        <div class="tertiary-nav d-none d-md-block">
          <div class="container">
            <div class="p-t-b-15 d-flex justify-content-between nav-container">
              <div class="breadcrum-wrapper"><span><a href="/guide/" style="font-size: 14px; font-weight: 600; color: #000;">Docs</a></span></div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="main-container">
      <section id="content">
        <div class="content-wrapper">

          <section id="guide" lang="en">
            <div class="container">
              <div class="row">
                <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                  <!-- start body -->
                  <div class="page_header">
<strong>IMPORTANT</strong>: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
<a href="../current/index.html">current release documentation</a>.
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="rest-apis.html">REST APIs</a></span>
»
<span class="breadcrumb-link"><a href="search.html">Search APIs</a></span>
»
<span class="breadcrumb-node">Ranking Evaluation API</span>
</div>
<div class="navheader">
<span class="prev">
<a href="search-field-caps.html">« Field Capabilities API</a>
</span>
<span class="next">
<a href="security-api.html">Security APIs »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="search-rank-eval"></a>Ranking Evaluation API<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/search/rank-eval.asciidoc">edit</a>
</h2>
</div></div></div>
<p>Allows you to evaluate the quality of ranked search results over a set of
typical search queries.</p>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="search-rank-eval-api-request"></a>Request<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/search/rank-eval.asciidoc">edit</a>
</h3>
</div></div></div>
<p><code class="literal">GET /&lt;index&gt;/_rank_eval</code></p>
<p><code class="literal">POST /&lt;index&gt;/_rank_eval</code></p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="search-rank-eval-api-desc"></a>Description<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/search/rank-eval.asciidoc">edit</a>
</h3>
</div></div></div>
<p>The ranking evaluation API allows you to evaluate the quality of ranked search
results over a set of typical search queries. Given this set of queries and a
list of manually rated documents, the <code class="literal">_rank_eval</code> endpoint calculates and
returns typical information retrieval metrics like <em>mean reciprocal rank</em>,
<em>precision</em> or <em>discounted cumulative gain</em>.</p>
<p>Search quality evaluation starts with looking at the users of your search
application, and the things that they are searching for. Users have a specific
<em>information need</em>; for example, they are looking for gift in a web shop or want
to book a flight for their next holiday. They usually enter some search terms
into a search box or some other web form. All of this information, together with
meta information about the user (for example the browser, location, earlier
preferences and so on) then gets translated into a query to the underlying
search system.</p>
<p>The challenge for search engineers is to tweak this translation process from
user entries to a concrete query, in such a way that the search results contain
the most relevant information with respect to the user’s information need. This
can only be done if the search result quality is evaluated constantly across a
representative test suite of typical user queries, so that improvements in the
rankings for one particular query don’t negatively affect the ranking for
other types of queries.</p>
<p>In order to get started with search quality evaluation, you need three basic
things:</p>
<div class="olist orderedlist">
<ol class="orderedlist">
<li class="listitem">
A collection of documents you want to evaluate your query performance against,
usually one or more indices.
</li>
<li class="listitem">
A collection of typical search requests that users enter into your system.
</li>
<li class="listitem">
A set of document ratings that represent the documents' relevance with respect
to a search request.
</li>
</ol>
</div>
<p>It is important to note that one set of document ratings is needed per test
query, and that the relevance judgements are based on the information need of
the user that entered the query.</p>
<p>The ranking evaluation API provides a convenient way to use this information in
a ranking evaluation request to calculate different search evaluation metrics.
This gives you a first estimation of your overall search quality, as well as a
measurement to optimize against when fine-tuning various aspect of the query
generation in your application.</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="search-rank-eval-api-path-params"></a>Path parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/search/rank-eval.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">&lt;index&gt;</code>
</span>
</dt>
<dd>
(Required, string) Comma-separated list or wildcard expression of index names
used to limit the request.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="search-rank-eval-api-query-params"></a>Query parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/search/rank-eval.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">allow_no_indices</code>
</span>
</dt>
<dd>
<p>
(Optional, boolean) If <code class="literal">true</code>,
the request does <span class="strong strong"><strong>not</strong></span> return an error
if a wildcard expression
or <code class="literal">_all</code> value retrieves only missing or closed indices.
</p>
<p>This parameter also applies to <a class="xref" href="indices-aliases.html" title="Update index alias API">index aliases</a>
that point to a missing or closed index.</p>
<p>Defaults to <code class="literal">true</code>.</p>
</dd>
<dt>
<span class="term">
<code class="literal">expand_wildcards</code>
</span>
</dt>
<dd>
<p>(Optional, string) Controls what kind of indices that wildcard expressions can
expand to. Multiple values are accepted when separated by a comma, as in
<code class="literal">open,hidden</code>. Valid values are:</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">all</code>
</span>
</dt>
<dd>
Expand to open and closed indices, including <a class="xref" href="index-modules.html#index-hidden">hidden indices</a>.
</dd>
<dt>
<span class="term">
<code class="literal">open</code>
</span>
</dt>
<dd>
Expand only to open indices.
</dd>
<dt>
<span class="term">
<code class="literal">closed</code>
</span>
</dt>
<dd>
Expand only to closed indices.
</dd>
<dt>
<span class="term">
<code class="literal">hidden</code>
</span>
</dt>
<dd>
Expansion of wildcards will include <a class="xref" href="index-modules.html#index-hidden">hidden indices</a>.
Must be combined with <code class="literal">open</code>, <code class="literal">closed</code>, or both.
</dd>
<dt>
<span class="term">
<code class="literal">none</code>
</span>
</dt>
<dd>
Wildcard expressions are not accepted.
</dd>
</dl>
</div>
<p>Defaults to <code class="literal">open</code>.</p>
</dd>
<dt>
<span class="term">
<code class="literal">ignore_unavailable</code>
</span>
</dt>
<dd>
(Optional, boolean) If <code class="literal">true</code>, missing or closed indices are not included in the
response. Defaults to <code class="literal">false</code>.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="search-rank-eval-api-example"></a>Examples<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/search/rank-eval.asciidoc">edit</a>
</h3>
</div></div></div>
<p>In its most basic form, a request to the <code class="literal">_rank_eval</code> endpoint has two sections:</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">GET /my_index/_rank_eval
{
    "requests": [ ... ], <a id="CO643-1"></a><i class="conum" data-value="1"></i>
    "metric": { <a id="CO643-2"></a><i class="conum" data-value="2"></i>
      "mean_reciprocal_rank": { ... } <a id="CO643-3"></a><i class="conum" data-value="3"></i>
   }
}</pre>
</div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO643-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>a set of typical search requests, together with their provided ratings</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO643-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>definition of the evaluation metric to calculate</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO643-3"><i class="conum" data-value="3"></i></a></p>
</td>
<td align="left" valign="top">
<p>a specific metric and its parameters</p>
</td>
</tr>
</table>
</div>
<p>The request section contains several search requests typical to your
application, along with the document ratings for each particular search request.</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">GET /my_index/_rank_eval
{
    "requests": [
        {
            "id": "amsterdam_query", <a id="CO644-1"></a><i class="conum" data-value="1"></i>
            "request": { <a id="CO644-2"></a><i class="conum" data-value="2"></i>
                "query": { "match": { "text": "amsterdam" }}
            },
            "ratings": [ <a id="CO644-3"></a><i class="conum" data-value="3"></i>
                 { "_index": "my_index", "_id": "doc1", "rating": 0 },
                 { "_index": "my_index", "_id": "doc2", "rating": 3},
                 { "_index": "my_index", "_id": "doc3", "rating": 1 }
            ]
        },
        {
            "id": "berlin_query",
            "request": {
                "query": { "match": { "text": "berlin" }}
            },
            "ratings": [
                { "_index": "my_index", "_id": "doc1", "rating": 1 }
            ]
        }
    ]
  }</pre>
</div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO644-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>the search request’s id, used to group result details later</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO644-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>the query that is being evaluated</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO644-3"><i class="conum" data-value="3"></i></a></p>
</td>
<td align="left" valign="top">
<p>a list of document ratings, each entry containing the document’s <code class="literal">_index</code> and
<code class="literal">_id</code> together with the rating of the document’s relevance with regard to this
search request</p>
</td>
</tr>
</table>
</div>
<p>A document <code class="literal">rating</code> can be any integer value that expresses the relevance of the
document on a user-defined scale. For some of the metrics, just giving a binary
rating (for example <code class="literal">0</code> for irrelevant and <code class="literal">1</code> for relevant) will be sufficient,
while other metrics can use a more fine-grained scale.</p>
<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="_template_based_ranking_evaluation"></a>Template-based ranking evaluation<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/search/rank-eval.asciidoc">edit</a>
</h4>
</div></div></div>
<p>As an alternative to having to provide a single query per test request, it is
possible to specify query templates in the evaluation request and later refer to
them. This way, queries with a similar structure that differ only in their
parameters don’t have to be repeated all the time in the <code class="literal">requests</code> section.
In typical search systems, where user inputs usually get filled into a small
set of query templates, this helps make the evaluation request more succinct.</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">GET /my_index/_rank_eval
{
   [...]
  "templates": [
     {
        "id": "match_one_field_query",  <a id="CO645-1"></a><i class="conum" data-value="1"></i>
        "template": { <a id="CO645-2"></a><i class="conum" data-value="2"></i>
            "inline": {
                "query": {
                  "match": { "{{field}}": { "query": "{{query_string}}" }}
                }
            }
        }
     }
  ],
  "requests": [
      {
         "id": "amsterdam_query"
         "ratings": [ ... ],
         "template_id": "match_one_field_query", <a id="CO645-3"></a><i class="conum" data-value="3"></i>
         "params": { <a id="CO645-4"></a><i class="conum" data-value="4"></i>
            "query_string": "amsterdam",
            "field": "text"
          }
     },
    [...]
}</pre>
</div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO645-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>the template id</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO645-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>the template definition to use</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO645-3"><i class="conum" data-value="3"></i></a></p>
</td>
<td align="left" valign="top">
<p>a reference to a previously defined template</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO645-4"><i class="conum" data-value="4"></i></a></p>
</td>
<td align="left" valign="top">
<p>the parameters to use to fill the template</p>
</td>
</tr>
</table>
</div>
<p>It is also possible to use <a class="xref" href="search-template.html#pre-registered-templates" title="Store a search template">templates already stored</a>  in the cluster state by referencing their id in the templates section.</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">GET /my_index/_rank_eval
{
   [...]
  "templates": [
     {
        "id": "match_one_field_query",  <a id="CO646-1"></a><i class="conum" data-value="1"></i>
        "template": { <a id="CO646-2"></a><i class="conum" data-value="2"></i>
            "id": "match_one_field_query"
        }
     }
  ],
  "requests": [...]
}</pre>
</div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO646-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>the template id used for requests</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO646-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>the template id stored in the cluster state</p>
</td>
</tr>
</table>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="_available_evaluation_metrics"></a>Available evaluation metrics<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/search/rank-eval.asciidoc">edit</a>
</h4>
</div></div></div>
<p>The <code class="literal">metric</code> section determines which of the available evaluation metrics
will be used. The following metrics are supported:</p>
<h5>
<a id="k-precision"></a>Precision at K (P@k)<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/search/rank-eval.asciidoc">edit</a>
</h5>
<p>This metric measures the proportion of relevant results in the top k search results.
It’s a form of the well-known
<a href="https://en.wikipedia.org/wiki/Evaluation_measures_(information_retrieval)#Precision" class="ulink" target="_top">Precision</a>
metric that only looks at the top k documents. It is the fraction of relevant
documents in those first k results. A precision at 10 (P@10) value of 0.6 then
means 6 out of the 10 top hits are relevant with respect to the user’s
information need.</p>
<p>P@k works well as a simple evaluation metric that has the benefit of being easy
to understand and explain. Documents in the collection need to be rated as either
relevant or irrelevant with respect to the current query. P@k is a set-based
metric and does not take into account the position of the relevant documents
within the top k results, so a ranking of ten results that contains one
relevant result in position 10 is equally as good as a ranking of ten results
that contains one relevant result in position 1.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET /twitter/_rank_eval
{
    "requests": [
    {
        "id": "JFK query",
        "request": { "query": { "match_all": {}}},
        "ratings": []
    }],
    "metric": {
      "precision": {
        "k" : 20,
        "relevant_rating_threshold": 1,
        "ignore_unlabeled": false
      }
   }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/2054.console"></div>
<p>The <code class="literal">precision</code> metric takes the following optional parameters</p>
<div class="informaltable">
<table border="1" cellpadding="4px">
<colgroup>
<col class="col_1">
<col class="col_2">
</colgroup>
<thead>
<tr>
<th align="left" valign="top">Parameter</th>
<th align="left" valign="top">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left" valign="top"><p><code class="literal">k</code></p></td>
<td align="left" valign="top"><p>sets the maximum number of documents retrieved per query. This value will act in place of the usual <code class="literal">size</code> parameter
in the query. Defaults to 10.</p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">relevant_rating_threshold</code></p></td>
<td align="left" valign="top"><p>sets the rating threshold above which documents are considered to be
"relevant". Defaults to <code class="literal">1</code>.</p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">ignore_unlabeled</code></p></td>
<td align="left" valign="top"><p>controls how unlabeled documents in the search results are counted.
If set to <em>true</em>, unlabeled documents are ignored and neither count as relevant or irrelevant. Set to <em>false</em> (the default), they are treated as irrelevant.</p></td>
</tr>
</tbody>
</table>
</div>
<h5>
<a id="k-recall"></a>Recall at K (R@k)<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/search/rank-eval.asciidoc">edit</a>
</h5>
<p>This metric measures the total number of relevant results in the top k search
results. It’s a form of the well-known
<a href="https://en.wikipedia.org/wiki/Evaluation_measures_(information_retrieval)#Recall" class="ulink" target="_top">Recall</a>
metric. It is the fraction of relevant documents in those first k results
relative to all possible relevant results. A recall at 10 (R@10) value of 0.5 then
means 4 out of 8 relevant documents, with respect to the user’s information
need, were retrieved in the 10 top hits.</p>
<p>R@k works well as a simple evaluation metric that has the benefit of being easy
to understand and explain. Documents in the collection need to be rated as either
relevant or irrelevant with respect to the current query. R@k is a set-based
metric and does not take into account the position of the relevant documents
within the top k results, so a ranking of ten results that contains one
relevant result in position 10 is equally as good as a ranking of ten results
that contains one relevant result in position 1.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET /twitter/_rank_eval
{
    "requests": [
    {
        "id": "JFK query",
        "request": { "query": { "match_all": {}}},
        "ratings": []
    }],
    "metric": {
      "recall": {
        "k" : 20,
        "relevant_rating_threshold": 1
      }
   }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/2055.console"></div>
<p>The <code class="literal">recall</code> metric takes the following optional parameters</p>
<div class="informaltable">
<table border="1" cellpadding="4px">
<colgroup>
<col class="col_1">
<col class="col_2">
</colgroup>
<thead>
<tr>
<th align="left" valign="top">Parameter</th>
<th align="left" valign="top">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left" valign="top"><p><code class="literal">k</code></p></td>
<td align="left" valign="top"><p>sets the maximum number of documents retrieved per query. This value will act in place of the usual <code class="literal">size</code> parameter
in the query. Defaults to 10.</p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">relevant_rating_threshold</code></p></td>
<td align="left" valign="top"><p>sets the rating threshold above which documents are considered to be
"relevant". Defaults to <code class="literal">1</code>.</p></td>
</tr>
</tbody>
</table>
</div>
<h5>
<a id="_mean_reciprocal_rank"></a>Mean reciprocal rank<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/search/rank-eval.asciidoc">edit</a>
</h5>
<p>For every query in the test suite, this metric calculates the reciprocal of the
rank of the first relevant document. For example, finding the first relevant
result in position 3 means the reciprocal rank is 1/3. The reciprocal rank for
each query is averaged across all queries in the test suite to give the
<a href="https://en.wikipedia.org/wiki/Mean_reciprocal_rank" class="ulink" target="_top">mean reciprocal rank</a>.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET /twitter/_rank_eval
{
    "requests": [
    {
        "id": "JFK query",
        "request": { "query": { "match_all": {}}},
        "ratings": []
    }],
    "metric": {
        "mean_reciprocal_rank": {
            "k" : 20,
            "relevant_rating_threshold" : 1
        }
    }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/2056.console"></div>
<p>The <code class="literal">mean_reciprocal_rank</code> metric takes the following optional parameters</p>
<div class="informaltable">
<table border="1" cellpadding="4px">
<colgroup>
<col class="col_1">
<col class="col_2">
</colgroup>
<thead>
<tr>
<th align="left" valign="top">Parameter</th>
<th align="left" valign="top">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left" valign="top"><p><code class="literal">k</code></p></td>
<td align="left" valign="top"><p>sets the maximum number of documents retrieved per query. This value will act in place of the usual <code class="literal">size</code> parameter
in the query. Defaults to 10.</p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">relevant_rating_threshold</code></p></td>
<td align="left" valign="top"><p>Sets the rating threshold above which documents are considered to be
"relevant". Defaults to <code class="literal">1</code>.</p></td>
</tr>
</tbody>
</table>
</div>
<h5>
<a id="_discounted_cumulative_gain_dcg"></a>Discounted cumulative gain (DCG)<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/search/rank-eval.asciidoc">edit</a>
</h5>
<p>In contrast to the two metrics above,
<a href="https://en.wikipedia.org/wiki/Discounted_cumulative_gain" class="ulink" target="_top">discounted cumulative gain</a>
takes both the rank and the rating of the search results into account.</p>
<p>The assumption is that highly relevant documents are more useful for the user
when appearing at the top of the result list. Therefore, the DCG formula reduces
the contribution that high ratings for documents on lower search ranks have on
the overall DCG metric.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET /twitter/_rank_eval
{
    "requests": [
    {
        "id": "JFK query",
        "request": { "query": { "match_all": {}}},
        "ratings": []
    }],
    "metric": {
       "dcg": {
            "k" : 20,
            "normalize": false
       }
    }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/2057.console"></div>
<p>The <code class="literal">dcg</code> metric takes the following optional parameters:</p>
<div class="informaltable">
<table border="1" cellpadding="4px">
<colgroup>
<col class="col_1">
<col class="col_2">
</colgroup>
<thead>
<tr>
<th align="left" valign="top">Parameter</th>
<th align="left" valign="top">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left" valign="top"><p><code class="literal">k</code></p></td>
<td align="left" valign="top"><p>sets the maximum number of documents retrieved per query. This value will act in place of the usual <code class="literal">size</code> parameter
in the query. Defaults to 10.</p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">normalize</code></p></td>
<td align="left" valign="top"><p>If set to <code class="literal">true</code>, this metric will calculate the <a href="https://en.wikipedia.org/wiki/Discounted_cumulative_gain#Normalized_DCG" class="ulink" target="_top">Normalized DCG</a>.</p></td>
</tr>
</tbody>
</table>
</div>
<h5>
<a id="_expected_reciprocal_rank_err"></a>Expected Reciprocal Rank (ERR)<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/search/rank-eval.asciidoc">edit</a>
</h5>
<p>Expected Reciprocal Rank (ERR) is an extension of the classical reciprocal rank
for the graded relevance case (Olivier Chapelle, Donald Metzler, Ya Zhang, and
Pierre Grinspan. 2009.
<a href="http://olivier.chapelle.cc/pub/err.pdf" class="ulink" target="_top">Expected reciprocal rank for graded relevance</a>.)</p>
<p>It is based on the assumption of a cascade model of search, in which a user
scans through ranked search results in order and stops at the first document
that satisfies the information need. For this reason, it is a good metric for
question answering and navigation queries, but less so for survey-oriented
information needs where the user is interested in finding many relevant
documents in the top k results.</p>
<p>The metric models the expectation of the reciprocal of the position at which a
user stops reading through the result list. This means that a relevant document
in a top ranking position will have a large contribution to the overall score.
However, the same document will contribute much less to the score if it appears
in a lower rank; even more so if there are some relevant (but maybe less relevant)
documents preceding it. In this way, the ERR metric discounts documents that
are shown after very relevant documents. This introduces a notion of dependency
in the ordering of relevant documents that e.g. Precision or DCG don’t account
for.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET /twitter/_rank_eval
{
    "requests": [
    {
        "id": "JFK query",
        "request": { "query": { "match_all": {}}},
        "ratings": []
    }],
    "metric": {
       "expected_reciprocal_rank": {
            "maximum_relevance" : 3,
            "k" : 20
       }
    }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/2058.console"></div>
<p>The <code class="literal">expected_reciprocal_rank</code> metric takes the following parameters:</p>
<div class="informaltable">
<table border="1" cellpadding="4px">
<colgroup>
<col class="col_1">
<col class="col_2">
</colgroup>
<thead>
<tr>
<th align="left" valign="top">Parameter</th>
<th align="left" valign="top">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left" valign="top"><p><code class="literal">maximum_relevance</code></p></td>
<td align="left" valign="top"><p>Mandatory parameter. The highest relevance grade used in the user-supplied
relevance judgments.</p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">k</code></p></td>
<td align="left" valign="top"><p>sets the maximum number of documents retrieved per query. This value will act in place of the usual <code class="literal">size</code> parameter
in the query. Defaults to 10.</p></td>
</tr>
</tbody>
</table>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="_response_format_2"></a>Response format<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/search/rank-eval.asciidoc">edit</a>
</h4>
</div></div></div>
<p>The response of the <code class="literal">_rank_eval</code> endpoint contains the overall calculated result
for the defined quality metric, a <code class="literal">details</code> section with a breakdown of results
for each query in the test suite and an optional <code class="literal">failures</code> section that shows
potential errors of individual queries. The response has the following format:</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">{
    "rank_eval": {
        "metric_score": 0.4, <a id="CO647-1"></a><i class="conum" data-value="1"></i>
        "details": {
            "my_query_id1": { <a id="CO647-2"></a><i class="conum" data-value="2"></i>
                "metric_score": 0.6, <a id="CO647-3"></a><i class="conum" data-value="3"></i>
                "unrated_docs": [ <a id="CO647-4"></a><i class="conum" data-value="4"></i>
                    {
                        "_index": "my_index",
                        "_id": "1960795"
                    }, [...]
                ],
                "hits": [
                    {
                        "hit": { <a id="CO647-5"></a><i class="conum" data-value="5"></i>
                            "_index": "my_index",
                            "_type": "page",
                            "_id": "1528558",
                            "_score": 7.0556192
                        },
                        "rating": 1
                    }, [...]
                ],
                "metric_details": { <a id="CO647-6"></a><i class="conum" data-value="6"></i>
                    "precision" : {
                        "relevant_docs_retrieved": 6,
                        "docs_retrieved": 10
                    }
                }
            },
            "my_query_id2" : { [...] }
        },
        "failures": { [...] }
    }
}</pre>
</div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO647-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>the overall evaluation quality calculated by the defined metric</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO647-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>the <code class="literal">details</code> section contains one entry for every query in the original <code class="literal">requests</code> section, keyed by the search request id</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO647-3"><i class="conum" data-value="3"></i></a></p>
</td>
<td align="left" valign="top">
<p>the <code class="literal">metric_score</code> in the <code class="literal">details</code> section shows the contribution of this query to the global quality metric score</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO647-4"><i class="conum" data-value="4"></i></a></p>
</td>
<td align="left" valign="top">
<p>the <code class="literal">unrated_docs</code> section contains an <code class="literal">_index</code> and <code class="literal">_id</code> entry for each document in the search result for this
query that didn’t have a ratings value. This can be used to ask the user to supply ratings for these documents</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO647-5"><i class="conum" data-value="5"></i></a></p>
</td>
<td align="left" valign="top">
<p>the <code class="literal">hits</code> section shows a grouping of the search results with their supplied ratings</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO647-6"><i class="conum" data-value="6"></i></a></p>
</td>
<td align="left" valign="top">
<p>the <code class="literal">metric_details</code> give additional information about the calculated quality metric (e.g. how many of the retrieved
documents were relevant). The content varies for each metric but allows for better interpretation of the results</p>
</td>
</tr>
</table>
</div>
</div>

</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="search-field-caps.html">« Field Capabilities API</a>
</span>
<span class="next">
<a href="security-api.html">Security APIs »</a>
</span>
</div>
</div>

                  <!-- end body -->
                </div>
                <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                  <div id="rtpcontainer" style="display: block;">
                    <div class="mktg-promo">
                      <h3>Most Popular</h3>
                      <ul class="icons">
                        <li class="icon-elasticsearch-white"><a href="https://www.elastic.co/webinars/getting-started-elasticsearch?baymax=default&amp;elektra=docs&amp;storm=top-video">Get Started with Elasticsearch: Video</a></li>
                        <li class="icon-kibana-white"><a href="https://www.elastic.co/webinars/getting-started-kibana?baymax=default&amp;elektra=docs&amp;storm=top-video">Intro to Kibana: Video</a></li>
                        <li class="icon-logstash-white"><a href="https://www.elastic.co/webinars/introduction-elk-stack?baymax=default&amp;elektra=docs&amp;storm=top-video">ELK for Logs &amp; Metrics: Video</a></li>
                      </ul>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </section>

        </div>


<div id="elastic-footer"></div>
<script src="https://www.elastic.co/elastic-footer.js"></script>
<!-- Footer Section end-->

      </section>
    </div>

<script src="/guide/static/jquery.js"></script>
<script type="text/javascript" src="/guide/static/docs.js"></script>
<script type="text/javascript">
  window.initial_state = {}</script>
  </body>
</html>
